#pragma once
#include"Hash.h"

namespace Unordered_map
{
	template<class K,class V,class Hash = HashFunc<K>>
	class unordered_map
	{
		struct Unordered_map_KeyOfT
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef Hash_Bucket::Hash_Table_Iterator<K, pair<const K, V>, Unordered_map_KeyOfT, Hash> iterator;
		iterator begin()
		{
			return _U_map.begin();
		}

		iterator end()
		{
			return _U_map.end();
		}

		pair<iterator,bool> insert(const pair<K, V>& kv)
		{
			return _U_map.Insert(kv);
		}

		V& operator[](const K& key)
		{
			pair<iterator, bool> pa = insert(make_pair(key, V()));

			return (*(pa.first)).second;
		}

		size_t size()
		{
			return _U_map.Size();
		}

		bool empty()
		{
			return _U_map.Empty();
		}

	private:
		Hash_Bucket::Hash_Table<K, pair<const K, V>, Unordered_map_KeyOfT,Hash> _U_map;
	};


	void test_map1()
	{
		unordered_map<string, string> dict;
		dict.insert(make_pair("sort", ""));
		dict.insert(make_pair("left", ""));
		dict.insert(make_pair("right", "&"));

		for (auto& kv : dict)
		{
			//kv.first += 'x';
			//kv.second += 'y';
			dict[kv.first] += 'Y';
			cout << kv.first << ":" << kv.second << endl;
		}
		cout << dict.size() << endl;
	}
}
